home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / bin / i2prouter < prev    next >
Encoding:
Text File  |  2012-10-27  |  68.1 KB  |  1,926 lines

  1. #!/bin/sh
  2.  
  3. #
  4. # Copyright (c) 1999, 2011 Tanuki Software, Ltd.
  5. # http://www.tanukisoftware.com
  6. # All rights reserved.
  7. #
  8. # Make sure that PIDFILE points to the correct location,
  9. # if you have changed the default location set in the
  10. # wrapper configuration file.
  11. #
  12. # If this script fails to successfully invoke i2psvc on your platform,
  13. # try the runplain.sh script instead.
  14. #
  15. # This software is the proprietary information of Tanuki Software.
  16. # You shall use it only in accordance with the terms of the
  17. # license agreement you entered into with Tanuki Software.
  18. # http://wrapper.tanukisoftware.com/doc/english/licenseOverview.html
  19. #
  20. # Java Service Wrapper sh script.  Suitable for starting and stopping
  21. #  wrapped Java applications on UNIX platforms.
  22. #
  23. #-----------------------------------------------------------------------------
  24. # These settings can be modified to fit the needs of your application
  25. # Optimized for use with version 3.5.14 of the Wrapper.
  26.  
  27. # Paths
  28. # Note that (percent)INSTALL_PATH, (percent)USER_HOME,  and (percent)SYSTEM_java_io_tmpdir
  29. # should have been replaced by the izpack installer.
  30. # If you did not run the installer, replace them with the appropriate paths.
  31. I2P="/usr/share/i2p"
  32. I2P_CONFIG_DIR="$HOME/.i2p"
  33. I2PTEMP="/tmp"
  34. # PORTABLE installation:
  35. # Use the following instead.
  36. #I2PTEMP="%INSTALL_PATH"
  37.  
  38. # Application
  39. APP_NAME="i2p"
  40. APP_LONG_NAME="I2P Service"
  41.  
  42. # gettext - we look for it in the path
  43. # fallback to echo is below, we can't set it to echo here.
  44. GETTEXT=$(which gettext > /dev/null 2>&1)
  45.  
  46. # Where to install the systemd service
  47. SYSTEMD_SERVICE="/etc/systemd/system/${APP_NAME}.service"
  48. if grep -q systemd /proc/1/comm ; then
  49.     USE_SYSTEMD=1
  50. fi
  51.  
  52. # If specified, the Wrapper will be run as the specified user.
  53. # IMPORTANT - Make sure that the user has the required privileges to write
  54. #  the PID file and wrapper.log files and that the directories exist.
  55. #  Failure to write the pid file will cause the Wrapper to exit.
  56. #  Failure to write the log file will cause the Wrapper to use CWD for the log file location.
  57. #
  58. # NOTE - This will set the user which is used to run the Wrapper as well as
  59. #  the JVM and is not useful in situations where a privileged resource or
  60. #  port needs to be allocated prior to the user being changed.
  61. #RUN_AS_USER=
  62.  
  63. # Wrapper
  64. WRAPPER_CMD="/usr/sbin/wrapper"
  65. WRAPPER_CONF="/etc/i2p/wrapper.config"
  66.  
  67. # Priority at which to run the wrapper.  See "man nice" for valid priorities.
  68. #  nice is only used if a priority is specified.
  69. PRIORITY=
  70.  
  71. # Location of the pid and status files.
  72. PIDDIR="$I2P_CONFIG_DIR"
  73. #PIDDIR="$I2PTEMP"
  74.  
  75. # Location of the wrapper.log file
  76. LOGDIR="$I2P_CONFIG_DIR"
  77. #LOGDIR="$I2PTEMP"
  78. LOGFILE="$LOGDIR/wrapper.log"
  79.  
  80. # If you'd like to run I2P as root (not recommended), uncomment the
  81. # following line
  82. #ALLOW_ROOT=true
  83.  
  84. # FIXED_COMMAND tells the script to use a hard coded action rather than
  85. # expecting the first parameter of the command line to be the command.
  86. # By default the command will will be expected to be the first parameter.
  87. #FIXED_COMMAND=console
  88.  
  89. # PASS_THROUGH tells the script to pass all arguments through to the JVM
  90. #  as is.  If FIXED_COMMAND is specified then all arguments will be passed.
  91. #  If not set then all arguments starting with the second will be passed.
  92. #PASS_THROUGH=true
  93.  
  94. # If uncommented, causes the Wrapper to be shutdown using an anchor file.
  95. #  When launched with the 'start' command, it will also ignore all INT and
  96. #  TERM signals.
  97. #IGNORE_SIGNALS=true
  98.  
  99. # Wrapper will start the JVM asynchronously. Your application may have some
  100. #  initialization tasks and it may be desirable to wait a few seconds
  101. #  before returning.  For example, to delay the invocation of following
  102. #  startup scripts.  Setting WAIT_AFTER_STARTUP to a positive number will
  103. #  cause the start command to delay for the indicated period of time
  104. #  (in seconds).
  105. #
  106. WAIT_AFTER_STARTUP=0
  107.  
  108. # If set, wait for the wrapper to report that the daemon has started
  109. WAIT_FOR_STARTED_STATUS=true
  110. WAIT_FOR_STARTED_TIMEOUT=120
  111.  
  112. # If set, the status, start_msg and stop_msg commands will print out detailed
  113. #   state information on the Wrapper and Java processes.
  114. #DETAIL_STATUS=true
  115.  
  116. # If set, the 'pause' and 'resume' commands will be enabled.  These make it
  117. #  possible to pause the JVM or Java application without completely stopping
  118. #  the Wrapper.  See the wrapper.pausable and wrapper.pausable.stop_jvm
  119. #  properties for more information.
  120. #PAUSABLE=true
  121.  
  122. # By default we show a detailed usage block.  Uncomment to show brief usage.
  123. #BRIEF_USAGE=true
  124.  
  125. # flag for using upstart when installing (rather than init.d rc.d)
  126. USE_UPSTART=
  127.  
  128. # Source the environment variables for the locale if $LANG isn't set
  129. # If you want to set custom locale variables for I2P,
  130. # you may comment out this block and set them yourself here.
  131.  
  132. if [ ! -n $LANG ]; then
  133.         for ENV_FILE in /etc/environment /etc/default/locale; do
  134.                 [ -r "$ENV_FILE" ] || continue
  135.                 [ -s "$ENV_FILE" ] || continue
  136.  
  137.                 for var in LANG LANGUAGE LC_ALL LC_CTYPE; do
  138.                         value=`egrep "^${var}=" "$ENV_FILE" | tail -n1 | cut -d= -f2`
  139.                         [ -n "$value" ] && eval export $var=$value
  140.                 done
  141.         done
  142. fi
  143.  
  144. # When installing on On Mac OSX platforms, the following domain will be used to
  145. #  prefix the plist file name.
  146. PLIST_DOMAIN=org.tanukisoftware.wrapper
  147.  
  148. # The following two lines are used by the chkconfig command. Change as is
  149. #  appropriate for your application.  They should remain commented.
  150. # chkconfig: 2345 20 80
  151. # description: I2P Service
  152.  
  153. # Initialization block for the install_initd and remove_initd scripts used by
  154. #  SUSE linux distributions.
  155. ### BEGIN INIT INFO
  156. # Provides: i2p
  157. # Required-Start: $local_fs $network $syslog
  158. # Should-Start:
  159. # Required-Stop:
  160. # Default-Start: 2 3 4 5
  161. # Default-Stop: 0 1 6
  162. # Short-Description: I2P Service
  163. # Description: I2P is a load-balanced unspoofable packet switching network
  164. ### END INIT INFO
  165.  
  166. # Do not modify anything beyond this point
  167. #-----------------------------------------------------------------------------
  168. if [ ! -e "$WRAPPER_CONF" ]; then
  169.        echo "Starting I2P Failed: Unable to find $WRAPPER_CONF"
  170.        exit 1
  171. fi
  172.  
  173. # Workaround for Gentoo
  174. JAVABINARY=$(awk -F'=' '/^ *wrapper\.java\.command/{print $2}' "$WRAPPER_CONF")
  175.  
  176. if [ -e /etc/gentoo-release ]; then
  177.     if [ $JAVABINARY = java ]; then
  178.         if [ -x /etc/java-config-2/current-system-vm/bin/java ]; then
  179.             JAVABINARY="/etc/java-config-2/current-system-vm/bin/java"
  180.         else
  181.             echo "Please set wrapper.java.command in $WRAPPER_CONF"
  182.             exit 1
  183.         fi
  184.     fi
  185. fi
  186.  
  187. WRAPPER_URL="http://www.i2p2.de/manualwrapper"
  188. unsupported() {
  189.     echo "The most likely reason is that a supported version of the java"
  190.     echo "wrapper is not available in the I2P installation package for your"
  191.     echo "platform. It may be possible to manually download and install"
  192.     echo "a compatible wrapper for your system."
  193.     echo "See ${WRAPPER_URL} for hints."
  194.     echo
  195.     echo "In the meantime, you may start I2P by running the script"
  196.     echo "${I2P}/runplain.sh"
  197.     echo
  198. }
  199.  
  200. failed() {
  201.         echo "**Failed to load the wrapper**"
  202.         case `uname -s` in
  203.              FreeBSD)
  204.                 echo
  205.                 echo "The wrapper requires libiconv to be on your system."
  206.                 echo "It can be installed with pkg_add -r libiconv"
  207.                 echo
  208.                 exit 1
  209.                 ;;
  210.              *)
  211.                 echo
  212.                 unsupported
  213.                 exit 1
  214.                 ;;
  215.         esac
  216. }
  217.  
  218. if [ -n "$FIXED_COMMAND" ]
  219. then
  220.     COMMAND="$FIXED_COMMAND"
  221. else
  222.     COMMAND="$1"
  223. fi
  224.  
  225.  
  226. # Required for HP-UX Startup
  227. if [ `uname -s` = "HP-UX" -o `uname -s` = "HP-UX64" ] ; then
  228.         PATH=$PATH:/usr/bin
  229. fi
  230.  
  231. # Get the fully qualified path to the script
  232. case $0 in
  233.     /*)
  234.         SCRIPT="$0"
  235.         ;;
  236.     *)
  237.         PWD=`pwd`
  238.         SCRIPT="$PWD/$0"
  239.         ;;
  240. esac
  241.  
  242. # Resolve the true real path without any sym links.
  243. CHANGED=true
  244. while [ "X$CHANGED" != "X" ]
  245. do
  246.     # Change spaces to ":" so the tokens can be parsed.
  247.     SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
  248.     # Get the real path to this script, resolving any symbolic links
  249.     TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
  250.     REALPATH=
  251.     for C in $TOKENS; do
  252.         # Change any ":" in the token back to a space.
  253.         C=`echo $C | sed -e 's;:; ;g'`
  254.         REALPATH="$REALPATH/$C"
  255.         # If REALPATH is a sym link, resolve it.  Loop for nested links.
  256.         while [ -h "$REALPATH" ] ; do
  257.             LS="`ls -ld "$REALPATH"`"
  258.             LINK="`expr "$LS" : '.*-> \(.*\)$'`"
  259.             if expr "$LINK" : '/.*' > /dev/null; then
  260.                 # LINK is absolute.
  261.                 REALPATH="$LINK"
  262.             else
  263.                 # LINK is relative.
  264.                 REALPATH="`dirname "$REALPATH"`""/$LINK"
  265.             fi
  266.         done
  267.     done
  268.  
  269.     if [ "$REALPATH" = "$SCRIPT" ]
  270.     then
  271.         CHANGED=""
  272.     else
  273.         SCRIPT="$REALPATH"
  274.     fi
  275. done
  276.  
  277. # Get the location of the script.
  278. REALDIR=`dirname "$REALPATH"`
  279. # Normalize the path
  280. REALDIR=`cd "${REALDIR}"; pwd`
  281.  
  282. # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
  283. #  the working directory is later changed.
  284. FIRST_CHAR=`echo $PIDDIR | cut -c1,1`
  285. if [ "$FIRST_CHAR" != "/" ]
  286. then
  287.     PIDDIR=$REALDIR/$PIDDIR
  288. fi
  289. # Same test for WRAPPER_CMD
  290. FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1`
  291. if [ "$FIRST_CHAR" != "/" ]
  292. then
  293.     WRAPPER_CMD=$REALDIR/$WRAPPER_CMD
  294. fi
  295. # Same test for WRAPPER_CONF
  296. FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1`
  297. if [ "$FIRST_CHAR" != "/" ]
  298. then
  299.     WRAPPER_CONF=$REALDIR/$WRAPPER_CONF
  300. fi
  301.  
  302. # Process ID
  303. ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
  304. COMMANDFILE="$PIDDIR/$APP_NAME.command"
  305. STATUSFILE="$PIDDIR/$APP_NAME.status"
  306. JAVASTATUSFILE="$PIDDIR/$APP_NAME.java.status"
  307. PIDFILE="$PIDDIR/$APP_NAME.pid"
  308. LOCKDIR="/var/lock/subsys"
  309. LOCKFILE="$LOCKDIR/$APP_NAME"
  310. pid=""
  311.  
  312. # Resolve the location of the 'ps' command
  313. PSEXE="/usr/ucb/ps"
  314.     if [ ! -x "$PSEXE" ]
  315.     then
  316.         PSEXE="/usr/bin/ps"
  317.         if [ ! -x "$PSEXE" ]
  318.         then
  319.             PSEXE="/bin/ps"
  320.             if [ ! -x "$PSEXE" ]
  321.             then
  322.                 eval echo `gettext 'Unable to locate "ps".'`
  323.                 eval echo `gettext 'Please report this message along with the location of the command on your system.'`
  324.                 exit 1
  325.             fi
  326.         fi
  327.     fi
  328.  
  329. TREXE="/usr/bin/tr"
  330. if [ ! -x "$TREXE" ]
  331. then
  332.     TREXE="/bin/tr"
  333.     if [ ! -x "$TREXE" ]
  334.     then
  335.         eval echo `gettext 'Unable to locate "tr".'`
  336.         eval echo `gettext 'Please report this message along with the location of the command on your system.'`
  337.         exit 1
  338.     fi
  339. fi
  340.  
  341.  
  342. # Resolve the os
  343. DIST_OS=`uname -s | $TREXE "[A-Z]" "[a-z]" | $TREXE -d ' '`
  344. case "$DIST_OS" in
  345.     'sunos')
  346.         DIST_OS="solaris"
  347.         ;;
  348.     'hp-ux' | 'hp-ux64')
  349.         # HP-UX needs the XPG4 version of ps (for -o args)
  350.         DIST_OS="hpux"
  351.         UNIX95=""
  352.         export UNIX95
  353.         ;;
  354.     'darwin')
  355.         DIST_OS="macosx"
  356.         ;;
  357.     'unix_sv')
  358.         DIST_OS="unixware"
  359.         ;;
  360.     'os/390')
  361.         DIST_OS="zos"
  362.         ;;
  363. esac
  364.  
  365. # Resolve the architecture
  366. if [ "$DIST_OS" = "macosx" ]
  367. then
  368.     OS_VER=`sw_vers | grep ProductVersion | cut -d: -f2 | sed -e 's/[^0-9]*//'`
  369.     DIST_ARCH="universal"
  370.     if [ $(sysctl -n hw.cpu64bit_capable) -eq 1 ]; then
  371.         DIST_BITS="64"
  372.     else
  373.         DIST_BITS="32"
  374.     fi
  375.     APP_PLIST_BASE=${PLIST_DOMAIN}.${APP_NAME}
  376.     APP_PLIST=${APP_PLIST_BASE}.plist
  377. else
  378.     DIST_ARCH=
  379.     DIST_ARCH=`uname -p 2>/dev/null | $TREXE "[A-Z]" "[a-z]" | $TREXE -d ' '`
  380.     if [ "X$DIST_ARCH" = "X" ]
  381.     then
  382.         DIST_ARCH="unknown"
  383.     fi
  384.     if [ "$DIST_ARCH" = "unknown" ]
  385.     then
  386.         DIST_ARCH=`uname -m 2>/dev/null | $TREXE "[A-Z]" "[a-z]" | $TREXE -d ' '`
  387.     fi
  388.     case "$DIST_ARCH" in
  389.         'athlon' | 'i386' | 'i486' | 'i586' | 'i686')
  390.             DIST_ARCH="x86"
  391.             if [ "${DIST_OS}" = "solaris" ] ; then
  392.                 DIST_BITS=`isainfo -b`
  393.             else
  394.                 DIST_BITS="32"
  395.             fi
  396.             ;;
  397.         'amd64' | 'x86_64')
  398.             DIST_ARCH="x86"
  399.             DIST_BITS="64"
  400.             ;;
  401.         'ia32')
  402.             DIST_ARCH="ia"
  403.             DIST_BITS="32"
  404.             ;;
  405.         'ia64' | 'ia64n' | 'ia64w')
  406.             DIST_ARCH="ia"
  407.             DIST_BITS="64"
  408.             ;;
  409.         'ip27')
  410.             DIST_ARCH="mips"
  411.             DIST_BITS="32"
  412.             ;;
  413.         'power' | 'powerpc' | 'power_pc' | 'ppc64')
  414.             if [ "${DIST_ARCH}" = "ppc64" ] ; then
  415.                 DIST_BITS="64"
  416.             else
  417.                 DIST_BITS="32"
  418.             fi
  419.             DIST_ARCH="ppc"
  420.             if [ "${DIST_OS}" = "aix" ] ; then
  421.                 if [ `getconf KERNEL_BITMODE` -eq 64 ]; then
  422.                     DIST_BITS="64"
  423.                 else
  424.                     DIST_BITS="32"
  425.                 fi
  426.             fi
  427.             ;;
  428.         'pa_risc' | 'pa-risc')
  429.             DIST_ARCH="parisc"
  430.             if [ `getconf KERNEL_BITS` -eq 64 ]; then
  431.                 DIST_BITS="64"
  432.             else
  433.                 DIST_BITS="32"
  434.             fi
  435.             ;;
  436.         'sun4u' | 'sparcv9' | 'sparc')
  437.             DIST_ARCH="sparc"
  438.             DIST_BITS=`isainfo -b`
  439.             ;;
  440.         '9000/800' | '9000/785')
  441.             DIST_ARCH="parisc"
  442.             if [ `getconf KERNEL_BITS` -eq 64 ]; then
  443.                 DIST_BITS="64"
  444.             else
  445.                 DIST_BITS="32"
  446.             fi
  447.             ;;
  448.         '2064' | '2066' | '2084' | '2086' | '2094' | '2096' | '2097' | '2098' | '2817')
  449.             DIST_ARCH="390"
  450.             DIST_BITS="64"
  451.             ;;
  452.     esac
  453. fi
  454.  
  455. # OSX always places Java in the same location so we can reliably set JAVA_HOME
  456. if [ "$DIST_OS" = "macosx" ]
  457. then
  458.     if [ -z "$JAVA_HOME" ]; then
  459.         JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
  460.     fi
  461. fi
  462.  
  463. # Test Echo
  464. ECHOTEST=`echo -n "x"`
  465. if [ "$ECHOTEST" = "x" ]
  466. then
  467.     ECHOOPT="-n "
  468. else
  469.     ECHOOPT=""
  470. fi
  471.  
  472.  
  473. gettext() {
  474.     # Call external gettext using our own translation files.
  475.     # Don't attempt to translate via the wrapper,
  476.     # it probably isn't supported in the community edition.
  477.     if [ "X${LANG#en}" = "X$LANG" ] && [ $(which $GETTEXT > /dev/null 2>&1) ] ; then
  478.             TEXTDOMAINDIR=$I2P/locale $GETTEXT -d i2prouter "$1"
  479.             if [ $? != 0 ] ; then
  480.                 echo "$1"
  481.             fi
  482.         else
  483.             echo "$1"
  484.         fi
  485. }
  486.  
  487. outputFile() {
  488.     if [ -f "$1" ]
  489.     then
  490.         eval echo `gettext '  $1  Found but not executable.'`;
  491.     else
  492.         echo "  $1"
  493.     fi
  494. }
  495.  
  496. # Decide on the wrapper binary to use.
  497. # If the bits of the OS could be detected, we will try to look for the
  498. #  binary with the correct bits value.  If it doesn't exist, fall back
  499. #  and look for the 32-bit binary.  If that doesn't exist either then
  500. #  look for the default.
  501. WRAPPER_TEST_CMD=""
  502. if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS" ]
  503. then
  504.     WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
  505.     if [ ! -x "$WRAPPER_TEST_CMD" ]
  506.     then
  507.         chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
  508.     fi
  509.     if [ -x "$WRAPPER_TEST_CMD" ]
  510.     then
  511.         WRAPPER_CMD="$WRAPPER_TEST_CMD"
  512.     else
  513.         outputFile "$WRAPPER_TEST_CMD"
  514.         WRAPPER_TEST_CMD=""
  515.     fi
  516. fi
  517. if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" -a -z "$WRAPPER_TEST_CMD" ]
  518. then
  519.     WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
  520.     if [ ! -x "$WRAPPER_TEST_CMD" ]
  521.     then
  522.         chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
  523.     fi
  524.     if [ -x "$WRAPPER_TEST_CMD" ]
  525.     then
  526.         WRAPPER_CMD="$WRAPPER_TEST_CMD"
  527.     else
  528.         outputFile "$WRAPPER_TEST_CMD"
  529.         WRAPPER_TEST_CMD=""
  530.     fi
  531. fi
  532. if [ -f "$WRAPPER_CMD" -a -z "$WRAPPER_TEST_CMD" ]
  533. then
  534.     WRAPPER_TEST_CMD="$WRAPPER_CMD"
  535.     if [ ! -x "$WRAPPER_TEST_CMD" ]
  536.     then
  537.         chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
  538.     fi
  539.     if [ -x "$WRAPPER_TEST_CMD" ]
  540.     then
  541.         WRAPPER_CMD="$WRAPPER_TEST_CMD"
  542.     else
  543.         outputFile "$WRAPPER_TEST_CMD"
  544.         WRAPPER_TEST_CMD=""
  545.     fi
  546. fi
  547. if [ -z "$WRAPPER_TEST_CMD" ]
  548. then
  549.     eval echo `gettext 'Unable to locate any of the following binaries:'`
  550.     outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
  551.     if [ ! "$DIST_BITS" = "32" ]
  552.     then
  553.         outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
  554.     fi
  555.     outputFile "$WRAPPER_CMD"
  556.  
  557.     exit 1
  558. fi
  559.  
  560. if [ ! -r "${WRAPPER_CMD}" ]; then
  561.     echo "Unable to locate ${WRAPPER_CMD} in ${I2P}!"
  562.     echo
  563.     unsupported
  564.     echo
  565.     exit 1
  566. fi
  567.  
  568. # Build the nice clause
  569. if [ "X$PRIORITY" = "X" ]
  570. then
  571.     CMDNICE=""
  572. else
  573.     CMDNICE="nice -$PRIORITY"
  574. fi
  575.  
  576. # Build the anchor file clause.
  577. if [ "X$IGNORE_SIGNALS" = "X" ]
  578. then
  579.    ANCHORPROP=
  580.    IGNOREPROP=
  581. else
  582.    ANCHORPROP=wrapper.anchorfile=\"$ANCHORFILE\"
  583.    IGNOREPROP=wrapper.ignore_signals=TRUE
  584. fi
  585.  
  586. # Build the status file clause.
  587. if [ "X$DETAIL_STATUS$WAIT_FOR_STARTED_STATUS" = "X" ]
  588. then
  589.    STATUSPROP=
  590. else
  591.    STATUSPROP="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
  592. fi
  593.  
  594. # Build the command file clause.
  595. if [ -n "$PAUSABLE" ]
  596. then
  597.    COMMANDPROP="wrapper.commandfile=\"$COMMANDFILE\" wrapper.pausable=TRUE"
  598. else
  599.    COMMANDPROP=
  600. fi
  601.  
  602. # Build the log file clause.
  603. LOGPROP="wrapper.logfile=\"$LOGFILE\""
  604.  
  605. if [ ! -n "$WAIT_FOR_STARTED_STATUS" ]
  606. then
  607.     WAIT_FOR_STARTED_STATUS=true
  608. fi
  609.  
  610. if [ $WAIT_FOR_STARTED_STATUS = true ] ; then
  611.     DETAIL_STATUS=true
  612. fi
  613.  
  614.  
  615. # Build the lock file clause.  Only create a lock file if the lock directory exists on this platform.
  616. LOCKPROP=
  617. if [ -d $LOCKDIR ]
  618. then
  619.     if [ -w $LOCKDIR ]
  620.     then
  621.         LOCKPROP=wrapper.lockfile=\"$LOCKFILE\"
  622.     fi
  623. fi
  624.  
  625. prepAdditionalParams() {
  626.     ADDITIONAL_PARA=""
  627.     if [ -n "$PASS_THROUGH" ] ; then
  628.         ADDITIONAL_PARA="--"
  629.     fi
  630.     while [ -n "$1" ] ; do
  631.         ADDITIONAL_PARA="$ADDITIONAL_PARA \"$1\""
  632.         shift
  633.     done
  634. }
  635.  
  636. checkUser() {
  637.     # $1 touchLock flag
  638.     # $2.. [command] args
  639.  
  640.     # Check the configured user.  If necessary rerun this script as the desired user.
  641.     if [ "X$RUN_AS_USER" != "X" ]
  642.     then
  643.         # Resolve the location of the 'id' command
  644.         IDEXE="/usr/xpg4/bin/id"
  645.         if [ ! -x "$IDEXE" ]
  646.         then
  647.             IDEXE="/usr/bin/id"
  648.             if [ ! -x "$IDEXE" ]
  649.             then
  650.                 eval echo `gettext 'Unable to locate "id".'`
  651.                 eval echo `gettext 'Please report this message along with the location of the command on your system.'`
  652.                 exit 1
  653.             fi
  654.         fi
  655.  
  656.         if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
  657.         then
  658.             # Already running as the configured user.  Avoid password prompts by not calling su.
  659.             RUN_AS_USER=""
  660.         fi
  661.     fi
  662.     if [ "X$RUN_AS_USER" != "X" ]
  663.     then
  664.         # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
  665.         # able to create the lock file.  The Wrapper will be able to update this file once it
  666.         # is created but will not be able to delete it on shutdown.  If $1 is set then
  667.         # the lock file should be created for the current command
  668.         if [ "X$LOCKPROP" != "X" ]
  669.         then
  670.             if [ "X$1" != "X" ]
  671.             then
  672.                 # Resolve the primary group
  673.                 RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
  674.                 if [ "X$RUN_AS_GROUP" = "X" ]
  675.                 then
  676.                     RUN_AS_GROUP=$RUN_AS_USER
  677.                 fi
  678.                 touch $LOCKFILE
  679.                 chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
  680.             fi
  681.         fi
  682.  
  683.         # Still want to change users, recurse.  This means that the user will only be
  684.         #  prompted for a password once. Variables shifted by 1
  685.         shift
  686.  
  687.         # Wrap the parameters so they can be passed.
  688.         ADDITIONAL_PARA=""
  689.         while [ -n "$1" ] ; do
  690.             ADDITIONAL_PARA="$ADDITIONAL_PARA \"$1\""
  691.             shift
  692.         done
  693.  
  694.         # Use "runuser" if this exists.  runuser should be used on RedHat in preference to su.
  695.         #
  696.         if test -f "/sbin/runuser"
  697.         then
  698.             /sbin/runuser - $RUN_AS_USER -c "\"$REALPATH\" $ADDITIONAL_PARA"
  699.         else
  700.             su - $RUN_AS_USER -c "\"$REALPATH\" $ADDITIONAL_PARA"
  701.         fi
  702.         RUN_AS_USER_EXITCODE=$?
  703.         # Now that we are the original user again, we may need to clean up the lock file.
  704.         if [ "X$LOCKPROP" != "X" ]
  705.         then
  706.             getpid
  707.             if [ "X$pid" = "X" ]
  708.             then
  709.                 # Wrapper is not running so make sure the lock file is deleted.
  710.                 if [ -f "$LOCKFILE" ]
  711.                 then
  712.                     rm "$LOCKFILE"
  713.                 fi
  714.             fi
  715.         fi
  716.  
  717.         exit $RUN_AS_USER_EXITCODE
  718.     fi
  719. }
  720.  
  721. getpid() {
  722.     pid=""
  723.     if [ -f "$PIDFILE" ]
  724.     then
  725.         if [ -r "$PIDFILE" ]
  726.         then
  727.             pid=`cat "$PIDFILE"`
  728.             if [ "X$pid" != "X" ]
  729.             then
  730.                 # It is possible that 'a' process with the pid exists but that it is not the
  731.                 #  correct process.  This can happen in a number of cases, but the most
  732.                 #  common is during system startup after an unclean shutdown.
  733.                 # The ps statement below looks for the specific wrapper command running as
  734.                 #  the pid.  If it is not found then the pid file is considered to be stale.
  735.                 case "$DIST_OS" in
  736.                     'freebsd')
  737.                         pidtest=`$PSEXE -p $pid -o args | tail -1`
  738.                         if [ "X$pidtest" = "XCOMMAND" ]
  739.                         then
  740.                             pidtest=""
  741.                         fi
  742.                         ;;
  743.                     'macosx')
  744.                         pidtest=`$PSEXE -ww -p $pid -o command | grep -F "$WRAPPER_CMD" | tail -1`
  745.                         ;;
  746.                     'solaris')
  747.                         if [ -f "/usr/bin/pargs" ]
  748.                         then
  749.                             pidtest=`pargs $pid | fgrep "$WRAPPER_CMD" | tail -1`
  750.                         else
  751.                             case "$PSEXE" in
  752.                             '/usr/ucb/ps')
  753.                                 pidtest=`$PSEXE -auxww  $pid | fgrep "$WRAPPER_CMD" | tail -1`
  754.                                 ;;
  755.                             '/usr/bin/ps')
  756.                                 TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
  757.                                 COUNT=`echo $TRUNCATED_CMD | wc -m`
  758.                                 COUNT=`echo ${COUNT}`
  759.                                 COUNT=`expr $COUNT - 1`
  760.                                 TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
  761.                                 pidtest=`$PSEXE -o comm -p $pid | fgrep "$TRUNCATED_CMD" | tail -1`
  762.                                 ;;
  763.                             '/bin/ps')
  764.                                 TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
  765.                                 COUNT=`echo $TRUNCATED_CMD | wc -m`
  766.                                 COUNT=`echo ${COUNT}`
  767.                                 COUNT=`expr $COUNT - 1`
  768.                                 TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
  769.                                 pidtest=`$PSEXE -o comm -p $pid | fgrep "$TRUNCATED_CMD" | tail -1`
  770.                                 ;;
  771.                             *)
  772.                                 echo "Unsupported ps command $PSEXE"
  773.                                 exit 1
  774.                                 ;;
  775.                             esac
  776.                         fi
  777.                         ;;
  778.                     'hpux')
  779.                         pidtest=`$PSEXE -p $pid -x -o args | grep -F "$WRAPPER_CMD" | tail -1`
  780.                         ;;
  781.                     *)
  782.                         pidtest=`$PSEXE -p $pid -o args | grep -F "$WRAPPER_CMD" | tail -1`
  783.                         ;;
  784.                 esac
  785.  
  786.                 if [ "X$pidtest" = "X" ]
  787.                 then
  788.                     # This is a stale pid file.
  789.                     rm -f "$PIDFILE"
  790.                     eval echo `gettext 'Removed stale pid file: $PIDFILE'`
  791.                     pid=""
  792.                 fi
  793.             fi
  794.         else
  795.             eval echo `gettext 'Cannot read $PIDFILE.'`
  796.             exit 1
  797.         fi
  798.     fi
  799. }
  800.  
  801. getstatus() {
  802.     STATUS=
  803.     if [ -f "$STATUSFILE" ]
  804.     then
  805.         if [ -r "$STATUSFILE" ]
  806.         then
  807.             STATUS=`cat "$STATUSFILE"`
  808.         fi
  809.     fi
  810.     if [ "X$STATUS" = "X" ]
  811.     then
  812.         STATUS="Unknown"
  813.     fi
  814.  
  815.     JAVASTATUS=
  816.     if [ -f "$JAVASTATUSFILE" ]
  817.     then
  818.         if [ -r "$JAVASTATUSFILE" ]
  819.         then
  820.             JAVASTATUS=`cat "$JAVASTATUSFILE"`
  821.         fi
  822.     fi
  823.     if [ "X$JAVASTATUS" = "X" ]
  824.     then
  825.         JAVASTATUS="Unknown"
  826.     fi
  827. }
  828.  
  829. testpid() {
  830.     case "$DIST_OS" in
  831.      'solaris')
  832.         case "$PSEXE" in
  833.         '/usr/ucb/ps')
  834.             pid=`$PSEXE  $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
  835.             ;;
  836.         '/usr/bin/ps')
  837.             pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
  838.             ;;
  839.         '/bin/ps')
  840.             pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
  841.             ;;
  842.         *)
  843.             echo "Unsupported ps command $PSEXE"
  844.             exit 1
  845.             ;;
  846.         esac
  847.         ;;
  848.     *)
  849.         pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 2>/dev/null
  850.         ;;
  851.     esac
  852.     if [ "X$pid" = "X" ]
  853.     then
  854.         # Process is gone so remove the pid file.
  855.         rm -f "$PIDFILE"
  856.         pid=""
  857.     fi
  858. }
  859.  
  860. launchdtrap() {
  861.     stopit
  862.     exit
  863. }
  864.  
  865. waitforwrapperstop() {
  866.     getpid
  867.     while [ "X$pid" != "X" ] ; do
  868.         sleep 1
  869.         getpid
  870.     done
  871. }
  872.  
  873. launchdinternal() {
  874.     getpid
  875.     trap launchdtrap TERM
  876.     if [ "X$pid" = "X" ]
  877.     then
  878.         prepAdditionalParams "$@"
  879.         mkdir -p "$PIDDIR" "$LOGDIR"
  880.  
  881.         # The string passed to eval must handles spaces in paths correctly.
  882.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $COMMANDPROP $LOCKPROP $LOGPROP $ADDITIONAL_PARA"
  883.         eval $COMMAND_LINE
  884.     else
  885.         eval echo `gettext '$APP_LONG_NAME is already running.'`
  886.         exit 1
  887.     fi
  888.     # launchd expects that this script stay up and running so we need to do our own monitoring of the Wrapper process.
  889.     if [ $WAIT_FOR_STARTED_STATUS = true ]
  890.     then
  891.         waitforwrapperstop
  892.     fi
  893. }
  894.  
  895. console() {
  896.     eval echo `gettext 'Running $APP_LONG_NAME...'`
  897.     getpid
  898.     if [ "X$pid" = "X" ]
  899.     then
  900.         trap '' 3 2
  901.  
  902.         prepAdditionalParams "$@"
  903.         mkdir -p "$PIDDIR" "$LOGDIR"
  904.  
  905.         # The string passed to eval must handles spaces in paths correctly.
  906.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.java.command=\"$JAVABINARY\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" $ANCHORPROP $STATUSPROP $COMMANDPROP $LOCKPROP $LOGPROP $ADDITIONAL_PARA"
  907.         eval $COMMAND_LINE
  908.         if [ "$?" -ne "0" ]; then
  909.                 failed
  910.         fi
  911.     else
  912.         eval echo `gettext '$APP_LONG_NAME is already running.'`
  913.         exit 1
  914.     fi
  915. }
  916.  
  917. waitforjavastartup() {
  918.     getstatus
  919.     eval echo $ECHOOPT `gettext 'Waiting for $APP_LONG_NAME...'`
  920.  
  921.     # Wait until the timeout or we have something besides Unknown.
  922.     counter=15
  923.     while [ "$JAVASTATUS" = "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
  924.         echo $ECHOOPT"."
  925.         sleep 1
  926.         getstatus
  927.         counter=`expr $counter - 1`
  928.     done
  929.  
  930.     if [ -n "$WAIT_FOR_STARTED_TIMEOUT" ] ; then
  931.         counter=$WAIT_FOR_STARTED_TIMEOUT
  932.     else
  933.         counter=120
  934.     fi
  935.     while [ "$JAVASTATUS" != "STARTED" -a "$JAVASTATUS" != "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
  936.         echo $ECHOOPT"."
  937.         sleep 1
  938.         getstatus
  939.         counter=`expr $counter - 1`
  940.     done
  941.     if [ "X$ECHOOPT" != "X" ] ; then
  942.         echo ""
  943.     fi
  944. }
  945.  
  946. startwait() {
  947.     if [ $WAIT_FOR_STARTED_STATUS = true ]
  948.     then
  949.         waitforjavastartup
  950.     fi
  951.     # Sleep for a few seconds to allow for intialization if required
  952.     #  then test to make sure we're still running.
  953.     #
  954.     i=0
  955.     while [ $i -lt $WAIT_AFTER_STARTUP ]
  956.     do
  957.         sleep 1
  958.         echo $ECHOOPT"."
  959.         i=`expr $i + 1`
  960.     done
  961.     if [ $WAIT_AFTER_STARTUP -gt 0 -o $WAIT_FOR_STARTED_STATUS = true ]
  962.     then
  963.         getpid
  964.         if [ "X$pid" = "X" ]
  965.         then
  966.             eval echo `gettext ' WARNING: $APP_LONG_NAME may have failed to start.'`
  967.             exit 1
  968.         else
  969.             eval echo `gettext ' running: PID:$pid'`
  970.         fi
  971.     else
  972.         echo ""
  973.     fi
  974. }
  975.  
  976. macosxstart() {
  977.     # The daemon has been installed.
  978.     eval echo `gettext 'Starting $APP_LONG_NAME.  Detected Mac OSX and installed launchd daemon.'`
  979.     if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
  980.         eval echo `gettext 'Must be root to perform this action.'`
  981.         exit 1
  982.     fi
  983.  
  984.     getpid
  985.     if [ "X$pid" != "X" ] ; then
  986.         eval echo `gettext '$APP_LONG_NAME is already running.'`
  987.         exit 1
  988.     fi
  989.  
  990.     # If the daemon was just installed, it may not be loaded.
  991.     LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
  992.     if [ "X${LOADED_PLIST}" = "X" ] ; then
  993.         launchctl load /Library/LaunchDaemons/${APP_PLIST}
  994.     fi
  995.     # If launchd is set to run the daemon already at Load, we don't need to call start
  996.     getpid
  997.     if [ "X$pid" = "X" ] ; then
  998.         launchctl start ${APP_PLIST_BASE}
  999.     fi
  1000.  
  1001.     startwait
  1002. }
  1003.  
  1004. upstartstart() {
  1005.     # The daemon has been installed.
  1006.     eval echo `gettext 'Starting $APP_LONG_NAME.  Detected Linux and installed upstart.'`
  1007.     if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
  1008.         eval echo `gettext 'Must be root to perform this action.'`
  1009.         exit 1
  1010.     fi
  1011.  
  1012.     getpid
  1013.     if [ "X$pid" != "X" ] ; then
  1014.         eval echo `gettext '$APP_LONG_NAME is already running.'`
  1015.         exit 1
  1016.     fi
  1017.  
  1018.     /sbin/start ${APP_NAME}
  1019.  
  1020.     startwait
  1021. }
  1022.  
  1023. start() {
  1024.     eval echo `gettext 'Starting $APP_LONG_NAME...'`
  1025.     getpid
  1026.     if [ "X$pid" = "X" ]
  1027.     then
  1028.         prepAdditionalParams "$@"
  1029.         mkdir -p "$PIDDIR" "$LOGDIR"
  1030.  
  1031.         # The string passed to eval must handles spaces in paths correctly.
  1032.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.java.command=\"$JAVABINARY\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $COMMANDPROP $LOCKPROP $LOGPROP $ADDITIONAL_PARA"
  1033.         eval $COMMAND_LINE
  1034.         if [ "$?" -ne "0" ]; then
  1035.                 failed
  1036.         fi
  1037.     else
  1038.         eval echo `gettext '$APP_LONG_NAME is already running.'`
  1039.         exit 1
  1040.     fi
  1041.  
  1042.     startwait
  1043. }
  1044.  
  1045.  
  1046. stopit() {
  1047.     # $1 exit if down flag
  1048.  
  1049.     eval echo `gettext 'Stopping $APP_LONG_NAME...'`
  1050.     getpid
  1051.     if [ "X$pid" = "X" ]
  1052.     then
  1053.         eval echo `gettext '$APP_LONG_NAME was not running.'`
  1054.         if [ "X$1" = "X1" ]
  1055.         then
  1056.             exit 1
  1057.         fi
  1058.     else
  1059.         if [ "X$IGNORE_SIGNALS" = "X" ]
  1060.         then
  1061.             # Running so try to stop it.
  1062.             kill -TERM $pid
  1063.             if [ $? -ne 0 ]
  1064.             then
  1065.                 # An explanation for the failure should have been given
  1066.                 eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
  1067.                 exit 1
  1068.             fi
  1069.         else
  1070.             rm -f "$ANCHORFILE"
  1071.             if [ -f "$ANCHORFILE" ]
  1072.             then
  1073.                 # An explanation for the failure should have been given
  1074.                 eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
  1075.                 exit 1
  1076.             fi
  1077.         fi
  1078.  
  1079.         # We can not predict how long it will take for the wrapper to
  1080.         #  actually stop as it depends on settings in wrapper.conf.
  1081.         #  Loop until it does.
  1082.         savepid=$pid
  1083.         CNT=0
  1084.         TOTCNT=0
  1085.         while [ "X$pid" != "X" ]
  1086.         do
  1087.             # Show a waiting message every 5 seconds.
  1088.             if [ "$CNT" -lt "5" ]
  1089.             then
  1090.                 CNT=`expr $CNT + 1`
  1091.             else
  1092.                 eval echo `gettext 'Waiting for $APP_LONG_NAME to exit...'`
  1093.                 CNT=0
  1094.             fi
  1095.             TOTCNT=`expr $TOTCNT + 1`
  1096.  
  1097.             sleep 1
  1098.  
  1099.             testpid
  1100.         done
  1101.  
  1102.         pid=$savepid
  1103.         testpid
  1104.         if [ "X$pid" != "X" ]
  1105.         then
  1106.             eval echo `gettext 'Failed to stop $APP_LONG_NAME.'`
  1107.             exit 1
  1108.         else
  1109.             eval echo `gettext 'Stopped $APP_LONG_NAME.'`
  1110.         fi
  1111.     fi
  1112. }
  1113.  
  1114. graceful() {
  1115.     # $1 exit if down flag
  1116.  
  1117.     eval echo `gettext 'Stopping $APP_LONG_NAME gracefully...'`
  1118.     getpid
  1119.     if [ "X$pid" = "X" ]
  1120.     then
  1121.         eval echo `gettext '$APP_LONG_NAME was not running.'`
  1122.         if [ "X$1" = "X1" ]
  1123.         then
  1124.             exit 1
  1125.         fi
  1126.     else
  1127.         if [ "X$IGNORE_SIGNALS" = "X" ]
  1128.         then
  1129.             # Running so try to stop it.
  1130.             # This sends HUP. router.gracefulHUP must be set in router.config,
  1131.             # or else this will do the same as stop.
  1132.             kill -HUP $pid
  1133.             if [ $? -ne 0 ]
  1134.             then
  1135.                 # An explanation for the failure should have been given
  1136.                 eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
  1137.                 exit 1
  1138.             fi
  1139.         else
  1140.             rm -f "$ANCHORFILE"
  1141.             if [ -f "$ANCHORFILE" ]
  1142.             then
  1143.                 # An explanation for the failure should have been given
  1144.                 eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
  1145.                 exit 1
  1146.             fi
  1147.         fi
  1148.     fi
  1149. }
  1150.  
  1151. pause() {
  1152.     eval echo `gettext 'Pausing $APP_LONG_NAME.'`
  1153. }
  1154.  
  1155. resume() {
  1156.     eval echo `gettext 'Resuming $APP_LONG_NAME.'`
  1157. }
  1158.  
  1159. status() {
  1160.     getpid
  1161.     if [ "X$pid" = "X" ]
  1162.     then
  1163.         eval echo `gettext '$APP_LONG_NAME is not running.'`
  1164.         exit 1
  1165.     else
  1166.         if [ "X$DETAIL_STATUS" = "X" ]
  1167.         then
  1168.             eval echo `gettext '$APP_LONG_NAME is running: PID:$pid'`
  1169.         else
  1170.             getstatus
  1171.             eval echo `gettext '$APP_LONG_NAME is running: PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS'`
  1172.         fi
  1173.         exit 0
  1174.     fi
  1175. }
  1176.  
  1177. installUpstart() {
  1178.     eval echo `gettext ' Installing the $APP_LONG_NAME daemon using upstart..'`
  1179.     if [ -f "${APP_NAME}.conf" ] ; then
  1180.         eval echo `gettext ' a custom upstart conf file ${APP_NAME}.conf found'`
  1181.         cp "${REALDIR}/${APP_NAME}.install" "/etc/init/${APP_NAME}.conf"
  1182.     else
  1183.         eval echo `gettext ' creating default upstart conf file..'`
  1184.         echo "# ${APP_NAME} - ${APP_LONG_NAME}" > "/etc/init/${APP_NAME}.conf"
  1185.         echo "description \"${APP_LONG_NAME}\"" >> "/etc/init/${APP_NAME}.conf"
  1186.         echo "author \"Tanuki Software Ltd. <info@tanukisoftware.com>\"" >> "/etc/init/${APP_NAME}.conf"
  1187.         echo "start on runlevel [2345]" >> "/etc/init/${APP_NAME}.conf"
  1188.         echo "stop on runlevel [!2345]" >> "/etc/init/${APP_NAME}.conf"
  1189.         echo "env LANG=${LANG}" >> "/etc/init/${APP_NAME}.conf"
  1190.        echo "exec \"${REALPATH}\" launchdinternal" >> "/etc/init/${APP_NAME}.conf"
  1191.     fi
  1192. }
  1193.  
  1194. installsystemd() {
  1195.     if [ -d "/etc/systemd/system/" ]; then
  1196.         cat << EOF >> "$SYSTEMD_SERVICE"
  1197. [Unit]
  1198. Description=$APP_LONG_NAME
  1199. After= local-fs.target network.target
  1200.  
  1201. [Service]
  1202. Type=forking
  1203. ExecStart=$I2P/i2prouter start
  1204. ExecReload=$I2P/i2prouter restart
  1205. ExecStop=$I2P/i2prouter stop
  1206. PIDFile=$I2P_CONFIG_DIR/i2p.pid
  1207.  
  1208. [Install]
  1209. WantedBy=multi-user.target
  1210. EOF
  1211.     systemctl --system daemon-reload > /dev/null 2>&1
  1212.     fi
  1213. }
  1214.  
  1215. installdaemon() {
  1216.     if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
  1217.         eval echo `gettext 'Must be root to perform this action.'`
  1218.         exit 1
  1219.     else
  1220.         APP_NAME_LOWER=`echo "$APP_NAME" | $TREXE "[A-Z]" "[a-z]"`
  1221.         if [ "$DIST_OS" = "solaris" ] ; then
  1222.             eval echo `gettext 'Detected Solaris:'`
  1223.             if [ -f /etc/init.d/$APP_NAME ] ; then
  1224.                 eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1225.                 exit 1
  1226.             else
  1227.                 eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1228.                 ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
  1229.                 ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
  1230.                 ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
  1231.             fi
  1232.         elif [ "$DIST_OS" = "linux" ] ; then
  1233.             if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ]  ; then
  1234.                 eval echo `gettext 'Detected RHEL or Fedora:'`
  1235.                 if [ -f "/etc/init.d/$APP_NAME" -o -f "/etc/init/${APP_NAME}.conf" ] ; then
  1236.                     eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1237.                     exit 1
  1238.                 else
  1239.                     if [ -n "$USE_UPSTART" -a -d "/etc/init" ] ; then
  1240.                         installUpstart
  1241.                     else
  1242.                         eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1243.                         ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
  1244.                         /sbin/chkconfig --add "$APP_NAME"
  1245.                         /sbin/chkconfig "$APP_NAME" on
  1246.                     fi
  1247.                 fi
  1248.             elif [ -f /etc/slackware-version ]; then
  1249.                 eval echo `gettext 'Detected Slackware Linux:'`
  1250.                 if [ -e "/etc/rc.d/rc.i2p" -o -f "/etc/rc.d/rc.i2p.new" ]; then
  1251.                     echo "Found initscript from I2P Slackpkg. Aborting." >&2
  1252.                     exit 1
  1253.                 else
  1254.                     if grep -q ${APP_NAME}router /etc/rc.d/rc.local > /dev/null 2>&1; then
  1255.                         eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1256.                         exit 1
  1257.                     else
  1258.                         echo "${REALDIR}/${APP_NAME}router start"  >> /etc/rc.d/rc.local
  1259.                         if [ ! -e /etc/rc.d/rc.local_shutdown ]; then
  1260.                             echo "#!/bin/sh" >> /etc/rc.d/rc.local_shutdown
  1261.                         fi
  1262.                         echo "${REALDIR}/${APP_NAME}router stop"  >> /etc/rc.d/rc.local_shutdown
  1263.                         chmod 755 /etc/rc.d/rc.local_shutdown
  1264.                     fi
  1265.                 fi
  1266.             elif [ -f /etc/arch-release ]; then
  1267.             eval echo `gettext 'Detected Arch Linux:'`
  1268.                 if [ -f "/etc/rc.d/i2prouter" -o -f "/usr/lib/systemd/system/i2prouter.service" ]; then
  1269.                     eval echo `gettext 'AUR package found. Refusing to continue.'`
  1270.                     exit 1
  1271.                 elif [ -f /etc/rc.d/i2p -a ! "$USE_SYSTEMD" = "1" ] || [ -f "$SYSTEMD_SERVICE" -a "$USE_SYSTEMD" = "1" ]; then
  1272.                     eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1273.                     exit 1
  1274.                 else
  1275.                         if [ ! -f "/etc/init.d/i2p" ]; then
  1276.                             if [ "$USE_SYSTEMD" != "1" ]; then
  1277.                                 echo "#!/bin/bash"  > /etc/rc.d/${APP_NAME}
  1278.                                 echo   >> /etc/rc.d/${APP_NAME}
  1279.                                 echo ". /etc/rc.conf"  >> /etc/rc.d/${APP_NAME}
  1280.                                 echo ". /etc/rc.d/functions"  >> /etc/rc.d/${APP_NAME}
  1281.                                 echo   >> /etc/rc.d/${APP_NAME}
  1282.                                 echo "case "\$1" in"  >> /etc/rc.d/${APP_NAME}
  1283.                                 echo "  start)"  >> /etc/rc.d/${APP_NAME}
  1284.                                 echo "    stat_busy \"Starting i2p-Router\""  >> /etc/rc.d/${APP_NAME}
  1285.                                 echo "    ${REALDIR}/${APP_NAME}router start >/dev/null 2>&1"  >> /etc/rc.d/${APP_NAME}
  1286.                                 echo "    if [ \$? -gt 0 ]; then"  >> /etc/rc.d/${APP_NAME}
  1287.                                 echo "      stat_fail"  >> /etc/rc.d/${APP_NAME}
  1288.                                 echo "    else"  >> /etc/rc.d/${APP_NAME}
  1289.                                 echo "      stat_done"  >> /etc/rc.d/${APP_NAME}
  1290.                                 echo "      add_daemon i2prouter"  >> /etc/rc.d/${APP_NAME}
  1291.                                 echo "    fi"  >> /etc/rc.d/${APP_NAME}
  1292.                                 echo "    ;;"  >> /etc/rc.d/${APP_NAME}
  1293.                                 echo "  stop)"  >> /etc/rc.d/${APP_NAME}
  1294.                                 echo "    stat_busy "Stopping i2p-Router""  >> /etc/rc.d/${APP_NAME}
  1295.                                 echo "    ${REALDIR}/${APP_NAME}router stop > /dev/null 2>&1"  >> /etc/rc.d/${APP_NAME}
  1296.                                 echo "    if [ \$? -gt 0 ]; then"  >> /etc/rc.d/${APP_NAME}
  1297.                                 echo "      stat_fail"  >> /etc/rc.d/${APP_NAME}
  1298.                                 echo "    else"  >> /etc/rc.d/${APP_NAME}
  1299.                                 echo "      stat_done"  >> /etc/rc.d/${APP_NAME}
  1300.                                 echo "      rm_daemon i2prouter"  >> /etc/rc.d/${APP_NAME}
  1301.                                 echo "    fi"  >> /etc/rc.d/${APP_NAME}
  1302.                                 echo "    ;;"  >> /etc/rc.d/${APP_NAME}
  1303.                                 echo "  restart)"  >> /etc/rc.d/${APP_NAME}
  1304.                                 echo "    ${REALDIR}/${APP_NAME}router restart"  >> /etc/rc.d/${APP_NAME}
  1305.                                 echo "    ;;"  >> /etc/rc.d/${APP_NAME}
  1306.                                 echo "  console)"  >> /etc/rc.d/${APP_NAME}
  1307.                                 echo "    ${REALDIR}/${APP_NAME}router console"  >> /etc/rc.d/${APP_NAME}
  1308.                                 echo "    ;;"  >> /etc/rc.d/${APP_NAME}
  1309.                                 echo "  status)"  >> /etc/rc.d/${APP_NAME}
  1310.                                 echo "    ${REALDIR}/${APP_NAME}router status"  >> /etc/rc.d/${APP_NAME}
  1311.                                 echo "    ;;"  >> /etc/rc.d/${APP_NAME}
  1312.                                 echo "  dump)"  >> /etc/rc.d/${APP_NAME}
  1313.                                 echo "    ${REALDIR}/${APP_NAME}router dump"  >> /etc/rc.d/${APP_NAME}
  1314.                                 echo "    ;;"  >> /etc/rc.d/${APP_NAME}
  1315.                                 echo "  graceful)"  >> /etc/rc.d/${APP_NAME}
  1316.                                 echo "    ${REALDIR}/${APP_NAME}router graceful"  >> /etc/rc.d/${APP_NAME}
  1317.                                 echo "    ;;"  >> /etc/rc.d/${APP_NAME}
  1318.                                 echo "  *)"  >> /etc/rc.d/${APP_NAME}
  1319.                                 echo "    echo \"usage: \$0 {start|stop|restart|console|status|dump}\""  >> /etc/rc.d/${APP_NAME}
  1320.                                 echo "    ;;"  >> /etc/rc.d/${APP_NAME}
  1321.                                 echo "esac"  >> /etc/rc.d/${APP_NAME}
  1322.                                 chmod 755 /etc/rc.d/${APP_NAME}
  1323.                                 chown root:root /etc/rc.d/${APP_NAME}
  1324.                                 eval echo `gettext ' The $APP_LONG_NAME daemon has been installed.'`
  1325.                                 eval echo `gettext ' Add \"i2p\" to the DAEMONS variable in /etc/rc.conf to enable.'`
  1326.                             else
  1327.                                 # We'll end up here if systemd is enabled.
  1328.                                 # If systemd is enabled we don't need the initscript
  1329.                                 rm -f /etc/rc.d/${APP_NAME}
  1330.                             fi
  1331.                         fi
  1332.                         if [ ! -f "${SYSTEMD_SERVICE}" ]; then
  1333.                             installsystemd
  1334.                         fi
  1335.                 fi
  1336.             elif [ -f /etc/SuSE-release ] ; then
  1337.                 eval echo `gettext 'Detected SuSE or SLES:'`
  1338.                  if [ -f /etc/rc.d/${APP_NAME} -a ! "$USE_SYSTEMD" = "1" ] || [ -f "$SYSTEMD_SERVICE" -a "$USE_SYSTEMD" = "1" ]; then
  1339.                     eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1340.                     exit 1
  1341.                 else
  1342.                     if [ ! -f "/etc/init.d/$APP_NAME" ]; then
  1343.                         if [ "$USE_SYSTEMD" != "1" ]; then
  1344.                             eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1345.                             ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
  1346.                             sed -i "s/Default-Start: 2 3 4 5/Default-Start: 5/" $0
  1347.                             insserv "/etc/init.d/$APP_NAME"
  1348.                         else
  1349.                             rm -f "/etc/init.d/$APP_NAME"
  1350.                         fi
  1351.                     fi
  1352.                     if [ ! -f "${SYSTEMD_SERVICE}" ]; then
  1353.                         installsystemd
  1354.                     fi
  1355.                 fi
  1356.             elif [ -f /etc/lsb-release -o -f /etc/debian_version ] ; then
  1357.                 eval echo `gettext 'Detected Debian-based distribution:'`
  1358.                 if [ -f "/etc/init.d/$APP_NAME" -o -f "/etc/init/${APP_NAME}.conf" ] ; then
  1359.                     eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1360.                     exit 1
  1361.                 else
  1362.                     if [ -n "$USE_UPSTART" -a -d "/etc/init" ] ; then
  1363.                         installUpstart
  1364.                     else
  1365.                         eval echo `gettext ' Installing the $APP_LONG_NAME daemon using init.d..'`
  1366.                         ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
  1367.                         update-rc.d "$APP_NAME" defaults
  1368.                     fi
  1369.                 fi
  1370.             else
  1371.                 eval echo `gettext 'Detected Linux:'`
  1372.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1373.                     eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1374.                     exit 1
  1375.                 else
  1376.                     eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1377.                     ln -s "$REALPATH" /etc/init.d/$APP_NAME
  1378.                     ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
  1379.                     ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
  1380.                     ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
  1381.                     ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/K20$APP_NAME_LOWER"
  1382.                 fi
  1383.             fi
  1384.         elif [ "$DIST_OS" = "hpux" ] ; then
  1385.             eval echo `gettext 'Detected HP-UX:'`
  1386.             if [ -f "/sbin/init.d/$APP_NAME" ] ; then
  1387.                 eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1388.                 exit 1
  1389.             else
  1390.                 eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1391.                 ln -s "$REALPATH" "/sbin/init.d/$APP_NAME"
  1392.                 ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/K20$APP_NAME_LOWER"
  1393.                 ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/S20$APP_NAME_LOWER"
  1394.             fi
  1395.         elif [ "$DIST_OS" = "aix" ] ; then
  1396.             eval echo `gettext 'Detected AIX:'`
  1397.             if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
  1398.                 eval echo `gettext ' The $APP_LONG_NAME daemon is already installed as rc.d script.'`
  1399.                 exit 1
  1400.             elif [ -n "`/usr/sbin/lsitab $APP_NAME`" -a -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
  1401.                 eval echo `gettext ' The $APP_LONG_NAME daemon is already installed as SRC service.'`
  1402.                 exit 1
  1403.             else
  1404.                 eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1405.                 if [ -n "`/usr/sbin/lsitab install_assist`" ] ; then
  1406.                     eval echo `gettext ' The task /usr/sbin/install_assist was found in the inittab, this might cause problems for all subsequent tasks to launch at this process is known to block the init task. Please make sure this task is not needed anymore and remove/deactivate it.'`
  1407.                 fi
  1408.                 /usr/bin/mkssys -s "$APP_NAME" -p "$REALPATH" -a "launchdinternal" -u 0 -f 9 -n 15 -S
  1409.                 /usr/sbin/mkitab "$APP_NAME":2:once:"/usr/bin/startsrc -s \"${APP_NAME}\" >/dev/console 2>&1"
  1410.  
  1411.             fi
  1412.         elif [ "$DIST_OS" = "freebsd" ] ; then
  1413.             eval echo `gettext 'Detected FreeBSD:'`
  1414.             if [ -f "/etc/rc.d/$APP_NAME" ] ; then
  1415.                 eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1416.                 exit 1
  1417.             else
  1418.                 eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1419.                 sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
  1420.                 if [ -f "${REALDIR}/${APP_NAME}.install" ] ; then
  1421.                     ln -s "${REALDIR}/${APP_NAME}.install" "/etc/rc.d/$APP_NAME"
  1422.                 else
  1423.                     echo '#!/bin/sh' > "/etc/rc.d/$APP_NAME"
  1424.                     echo "#" >> "/etc/rc.d/$APP_NAME"
  1425.                     echo "# PROVIDE: $APP_NAME" >> "/etc/rc.d/$APP_NAME"
  1426.                     echo "# REQUIRE: NETWORKING" >> "/etc/rc.d/$APP_NAME"
  1427.                     echo "# KEYWORD: shutdown" >> "/etc/rc.d/$APP_NAME"
  1428.                     echo ". /etc/rc.subr" >> "/etc/rc.d/$APP_NAME"
  1429.                     echo "name=\"$APP_NAME\"" >> "/etc/rc.d/$APP_NAME"
  1430.                     echo "rcvar=\`set_rcvar\`" >> "/etc/rc.d/$APP_NAME"
  1431.                     echo "command=\"${REALDIR}/${APP_NAME}router\"" >> "/etc/rc.d/$APP_NAME"
  1432.                     echo 'start_cmd="${name}_start"' >> "/etc/rc.d/$APP_NAME"
  1433.                     echo 'load_rc_config $name' >> "/etc/rc.d/$APP_NAME"
  1434.                     echo 'status_cmd="${name}_status"' >> "/etc/rc.d/$APP_NAME"
  1435.                     echo 'stop_cmd="${name}_stop"' >> "/etc/rc.d/$APP_NAME"
  1436.                     echo "${APP_NAME}_status() {" >> "/etc/rc.d/$APP_NAME"
  1437.                     echo '${command} status' >> "/etc/rc.d/$APP_NAME"
  1438.                     echo '}' >> "/etc/rc.d/$APP_NAME"
  1439.                     echo "${APP_NAME}_stop() {" >> "/etc/rc.d/$APP_NAME"
  1440.                     echo '${command} stop' >> "/etc/rc.d/$APP_NAME"
  1441.                     echo '}' >> "/etc/rc.d/$APP_NAME"
  1442.                     echo "${APP_NAME}_start() {" >> "/etc/rc.d/$APP_NAME"
  1443.                     echo '${command} start' >> "/etc/rc.d/$APP_NAME"
  1444.                     echo '}' >> "/etc/rc.d/$APP_NAME"
  1445.                     echo 'run_rc_command "$1"' >> "/etc/rc.d/$APP_NAME"
  1446.                 fi
  1447.                 echo "${APP_NAME}_enable=\"YES\"" >> /etc/rc.conf
  1448.                 chmod 555 "/etc/rc.d/$APP_NAME"
  1449.             fi
  1450.         elif [ "$DIST_OS" = "macosx" ] ; then
  1451.             eval echo `gettext 'Detected Mac OSX:'`
  1452.             if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
  1453.                 eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1454.                 exit 1
  1455.             else
  1456.                 eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1457.                 if [ -f "${REALDIR}/${APP_PLIST}" ] ; then
  1458.                     ln -s "${REALDIR}/${APP_PLIST}" "/Library/LaunchDaemons/${APP_PLIST}"
  1459.                 else
  1460.                     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "/Library/LaunchDaemons/${APP_PLIST}"
  1461.                     echo "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1462.                     echo "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1463.                     echo "<plist version=\"1.0\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1464.                     echo "    <dict>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1465.                     echo "        <key>Label</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1466.                     echo "        <string>${APP_PLIST_BASE}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1467.                     echo "        <key>ProgramArguments</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1468.                     echo "        <array>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1469.                     echo "            <string>${REALDIR}/${APP_NAME}router</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1470.                     echo "            <string>launchdinternal</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1471.                     echo "        </array>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1472.                     echo "        <key>OnDemand</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1473.                     echo "        <true/>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1474.                     echo "        <key>RunAtLoad</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1475.                     echo "        <true/>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1476.                     if [ "X$RUN_AS_USER" != "X" ] ; then
  1477.                         echo "        <key>UserName</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1478.                         echo "        <string>${RUN_AS_USER}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1479.                     fi
  1480.                     echo "    </dict>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1481.                     echo "</plist>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  1482.                 fi
  1483.                 chmod 555 "/Library/LaunchDaemons/${APP_PLIST}"
  1484.             fi
  1485.         elif [ "$DIST_OS" = "zos" ] ; then
  1486.             eval echo `gettext 'Detected z/OS:'`
  1487.             if [ -f /etc/rc.bak ] ; then
  1488.                 eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
  1489.                 exit 1
  1490.             else
  1491.                 eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
  1492.                 cp /etc/rc /etc/rc.bak
  1493.                 sed  "s:echo /etc/rc script executed, \`date\`::g" /etc/rc.bak > /etc/rc
  1494.                 echo "_BPX_JOBNAME='${APP_NAME}' \"${REALDIR}/${APP_NAME}router\" start" >>/etc/rc
  1495.                 echo '/etc/rc script executed, `date`' >>/etc/rc
  1496.             fi
  1497.         else
  1498.             eval echo `gettext 'Install not currently supported for $DIST_OS'`
  1499.             exit 1
  1500.         fi
  1501.     fi
  1502. }
  1503.  
  1504. removedaemon() {
  1505.     if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
  1506.         eval echo `gettext 'Must be root to perform this action.'`
  1507.         exit 1
  1508.     else
  1509.         stopit "0"
  1510.         APP_NAME_LOWER=`echo "$APP_NAME" | $TREXE "[A-Z]" "[a-z]"`
  1511.         if [ "$DIST_OS" = "solaris" ] ; then
  1512.             eval echo `gettext 'Detected Solaris:'`
  1513.             if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1514.                 eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1515.                 for i in "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME"
  1516.                 do
  1517.                     rm -f $i
  1518.                 done
  1519.             else
  1520.                 eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1521.                 exit 1
  1522.             fi
  1523.         elif [ "$DIST_OS" = "linux" ] ; then
  1524.             if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then
  1525.                 eval echo `gettext 'Detected RHEL or Fedora:'`
  1526.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1527.                     eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1528.                     /sbin/chkconfig "$APP_NAME" off
  1529.                     /sbin/chkconfig --del "$APP_NAME"
  1530.                     rm -f "/etc/init.d/$APP_NAME"
  1531.                 elif [ -f "/etc/init/${APP_NAME}.conf" ] ; then
  1532.                     eval echo `gettext ' Removing $APP_LONG_NAME daemon from upstart...'`
  1533.                     rm "/etc/init/${APP_NAME}.conf"
  1534.                 else
  1535.                     eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1536.                     exit 1
  1537.                 fi
  1538.             elif [ -f /etc/slackware-version ] ; then
  1539.                 eval echo `gettext 'Detected Slackware Linux:'`
  1540.                 if grep -q ${APP_NAME}router /etc/rc.d/rc.local > /dev/null 2>&1 ; then
  1541.                     eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1542.                     sed -i "/i2prouter/d" /etc/rc.d/rc.local /etc/rc.d/rc.local_shutdown
  1543.                 else
  1544.                     eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1545.                     exit 1
  1546.                 fi
  1547.             elif [ -f /etc/arch-release ] ; then
  1548.                 eval echo `gettext 'Detected Arch Linux:'`
  1549.                 if [ -f "/etc/rc.d/$APP_NAME" -o -f "$SYSTEMD_SERVICE" ] ; then
  1550.                     eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1551.                     rm -f "/etc/rc.d/$APP_NAME"
  1552.                     rm -f "$SYSTEMD_SERVICE"
  1553.                 else
  1554.                     eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1555.                     exit 1
  1556.                 fi
  1557.             elif [ -f /etc/SuSE-release ] ; then
  1558.                 eval echo `gettext 'Detected SuSE or SLES:'`
  1559.                 if [ -f "/etc/init.d/$APP_NAME" -o ${SYSTEMD_SERVICE} ] ; then
  1560.                     eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1561.                     insserv -r "/etc/init.d/$APP_NAME"
  1562.                     rm -f "/etc/init.d/$APP_NAME"
  1563.                     rm -f "$SYSTEMD_SERVICE"
  1564.                 else
  1565.                     eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1566.                     exit 1
  1567.                 fi
  1568.             elif [ -f /etc/lsb-release -o -f /etc/debian_version ] ; then
  1569.                 eval echo `gettext 'Detected Debian-based distribution:'`
  1570.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1571.                     eval echo `gettext ' Removing $APP_LONG_NAME daemon from init.d...'`
  1572.                     update-rc.d -f "$APP_NAME" remove
  1573.                     rm -f "/etc/init.d/$APP_NAME"
  1574.                 elif [ -f "/etc/init/${APP_NAME}.conf" ] ; then
  1575.                     eval echo `gettext ' Removing $APP_LONG_NAME daemon from upstart...'`
  1576.                     rm "/etc/init/${APP_NAME}.conf"
  1577.                 else
  1578.                     eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1579.                     exit 1
  1580.                 fi
  1581.             else
  1582.                 eval echo `gettext 'Detected Linux:'`
  1583.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1584.                     eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1585.                     for i in "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/rc5.d/K20$APP_NAME_LOWER" "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
  1586.                     do
  1587.                         rm -f $i
  1588.                     done
  1589.                 else
  1590.                     eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1591.                     exit 1
  1592.                 fi
  1593.             fi
  1594.         elif [ "$DIST_OS" = "hpux" ] ; then
  1595.             eval echo `gettext 'Detected HP-UX:'`
  1596.             if [ -f "/sbin/init.d/$APP_NAME" ] ; then
  1597.                 eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1598.                 for i in "/sbin/rc3.d/K20$APP_NAME_LOWER" "/sbin/rc3.d/S20$APP_NAME_LOWER" "/sbin/init.d/$APP_NAME"
  1599.                 do
  1600.                     rm -f $i
  1601.                 done
  1602.             else
  1603.                 eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1604.                 exit 1
  1605.             fi
  1606.         elif [ "$DIST_OS" = "aix" ] ; then
  1607.             eval echo `gettext 'Detected AIX:'`
  1608.             if [ -f "/etc/rc.d/init.d/$APP_NAME" -o -n "`/usr/sbin/lsitab $APP_NAME`" -o -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
  1609.                 eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1610.                 if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
  1611.                     for i in "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER" "/etc/rc.d/init.d/$APP_NAME"
  1612.                     do
  1613.                         rm -f $i
  1614.                     done
  1615.                 fi
  1616.                 if [ -n "`/usr/sbin/lsitab $APP_NAME`" -o -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
  1617.                     /usr/sbin/rmitab $APP_NAME
  1618.                     /usr/bin/rmssys -s $APP_NAME
  1619.                 fi
  1620.             else
  1621.                 eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1622.                 exit 1
  1623.             fi
  1624.         elif [ "$DIST_OS" = "freebsd" ] ; then
  1625.             eval echo `gettext 'Detected FreeBSD:'`
  1626.             if [ -f "/etc/rc.d/$APP_NAME" ] ; then
  1627.                 eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1628.                 for i in "/etc/rc.d/$APP_NAME"
  1629.                 do
  1630.                     rm -f $i
  1631.                 done
  1632.                 sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
  1633.             else
  1634.                 eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1635.                 exit 1
  1636.             fi
  1637.         elif [ "$DIST_OS" = "macosx" ] ; then
  1638.             eval echo `gettext 'Detected Mac OSX:'`
  1639.             if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
  1640.                 eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1641.                 # Make sure the plist is installed
  1642.                 LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
  1643.                 if [ "X${LOADED_PLIST}" != "X" ] ; then
  1644.                     launchctl unload "/Library/LaunchDaemons/${APP_PLIST}"
  1645.                 fi
  1646.                 rm -f "/Library/LaunchDaemons/${APP_PLIST}"
  1647.             else
  1648.                 eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1649.                 exit 1
  1650.             fi
  1651.         elif [ "$DIST_OS" = "zos" ] ; then
  1652.             eval echo `gettext 'Detected z/OS:'`
  1653.             if [ -f /etc/rc.bak ] ; then
  1654.                 eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
  1655.                 cp /etc/rc /etc/rc.bak
  1656.                 sed  "s/_BPX_JOBNAME=\'APP_NAME\'.*//g" /etc/rc.bak > /etc/rc
  1657.                 rm /etc/rc.bak
  1658.             else
  1659.                 eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
  1660.                 exit 1
  1661.             fi
  1662.         else
  1663.             eval echo `gettext 'Remove not currently supported for $DIST_OS'`
  1664.             exit 1
  1665.         fi
  1666.     fi
  1667. }
  1668.  
  1669. dump() {
  1670.     eval echo `gettext 'Dumping $APP_LONG_NAME...'`
  1671.     getpid
  1672.     if [ "X$pid" = "X" ]
  1673.     then
  1674.         eval echo `gettext '$APP_LONG_NAME was not running.'`
  1675.     else
  1676.         kill -3 $pid
  1677.  
  1678.         if [ $? -ne 0 ]
  1679.         then
  1680.             eval echo `gettext 'Failed to dump $APP_LONG_NAME.'`
  1681.             exit 1
  1682.         else
  1683.             eval echo `gettext 'Dumped $APP_LONG_NAME.'`
  1684.         fi
  1685.     fi
  1686. }
  1687.  
  1688. # Used by HP-UX init scripts.
  1689. startmsg() {
  1690.     getpid
  1691.     if [ "X$pid" = "X" ]
  1692.     then
  1693.         eval echo `gettext 'Starting $APP_LONG_NAME...  Wrapper:Stopped'`
  1694.     else
  1695.         if [ "X$DETAIL_STATUS" = "X" ]
  1696.         then
  1697.             eval echo `gettext 'Starting $APP_LONG_NAME...  Wrapper:Running'`
  1698.         else
  1699.             getstatus
  1700.             eval echo `gettext 'Starting $APP_LONG_NAME...  Wrapper:$STATUS, Java:$JAVASTATUS'`
  1701.         fi
  1702.     fi
  1703. }
  1704.  
  1705. # Used by HP-UX init scripts.
  1706. stopmsg() {
  1707.     getpid
  1708.     if [ "X$pid" = "X" ]
  1709.     then
  1710.         eval echo `gettext 'Stopping $APP_LONG_NAME...  Wrapper:Stopped'`
  1711.     else
  1712.         if [ "X$DETAIL_STATUS" = "X" ]
  1713.         then
  1714.             eval echo `gettext 'Stopping $APP_LONG_NAME...  Wrapper:Running'`
  1715.         else
  1716.             getstatus
  1717.             eval echo `gettext 'Stopping $APP_LONG_NAME...  Wrapper:$STATUS, Java:$JAVASTATUS'`
  1718.         fi
  1719.     fi
  1720. }
  1721.  
  1722. showUsage() {
  1723.     # $1 bad command
  1724.  
  1725.     if [ -n "$1" ]
  1726.     then
  1727.         eval echo `gettext 'Unexpected command: $1'`
  1728.         echo "";
  1729.     fi
  1730.  
  1731.     eval MSG=`gettext 'Usage: '`
  1732.     if [ -n "$FIXED_COMMAND" ] ; then
  1733.         if [ -n "$PASS_THROUGH" ] ; then
  1734.             echo "${MSG} $0 {JavaAppArgs}"
  1735.         else
  1736.             echo "${MSG} $0"
  1737.         fi
  1738.     else
  1739.         if [ -n "$PAUSABLE" ] ; then
  1740.             if [ -n "$PASS_THROUGH" ] ; then
  1741.                 echo "${MSG} $0 [ console {JavaAppArgs} | start {JavaAppArgs} | stop | restart {JavaAppArgs} | condrestart {JavaAppArgs} | pause | resume | status | install | remove | dump ]"
  1742.             else
  1743.                 echo "${MSG} $0 [ console | start | stop | restart | condrestart | pause | resume | status | install | remove | dump ]"
  1744.             fi
  1745.         else
  1746.             if [ -n "$PASS_THROUGH" ] ; then
  1747.                 echo "${MSG} $0 [ console {JavaAppArgs} | start {JavaAppArgs} | stop | restart {JavaAppArgs} | condrestart {JavaAppArgs} | status | install | remove | dump ]"
  1748.             else
  1749.                 echo "${MSG} $0 [ console | start | stop | restart | condrestart | status | install | remove | dump ]"
  1750.             fi
  1751.         fi
  1752.     fi
  1753.  
  1754.     if [ ! -n "$BRIEF_USAGE" ]
  1755.     then
  1756.         echo "";
  1757.         if [ ! -n "$FIXED_COMMAND" ] ; then
  1758.             echo "`gettext 'Commands:'`"
  1759.             echo "`gettext '  console      Launch in the current console.'`"
  1760.             echo "`gettext '  start        Start in the background as a daemon process.'`"
  1761.             echo "`gettext '  stop         Stop if running as a daemon or in another console.'`"
  1762.             echo "`gettext '  graceful     Stop gracefully, may take up to 11 minutes.'`"
  1763.             echo "`gettext '  restart      Stop if running and then start.'`"
  1764.             echo "`gettext '  condrestart  Restart only if already running.'`"
  1765.             if [ -n "$PAUSABLE" ] ; then
  1766.                 echo "`gettext '  pause        Pause if running.'`"
  1767.                 echo "`gettext '  resume       Resume if paused.'`"
  1768.             fi
  1769.             echo "`gettext '  status       Query the current status.'`"
  1770.             echo "`gettext '  install      Install to start automatically when system boots.'`"
  1771.             echo "`gettext '  remove       Uninstall.'`"
  1772.             echo "`gettext '  dump         Request a Java thread dump if running.'`"
  1773.             echo "";
  1774.         fi
  1775.         if [ -n "$PASS_THROUGH" ] ; then
  1776.             echo "`gettext 'JavaAppArgs: Zero or more arguments which will be passed to the Java application.'`"
  1777.             echo "";
  1778.         fi
  1779.     fi
  1780.  
  1781.     exit 1
  1782. }
  1783.  
  1784. showsetusermesg()  {
  1785.     echo "Please edit $0 and set the variable RUN_AS_USER."
  1786. }
  1787.  
  1788. checkifstartingasroot() {
  1789.     if [ ! `grep ^RUN_AS_USER $0` ] && [ ! `grep ^ALLOW_ROOT $0` ] && [ `id -ur` = '0' ]; then
  1790.         echo "Running I2P as the root user is *not* recommended."
  1791.         showsetusermesg
  1792.         echo
  1793.         echo "If you'd like to run as root anyway you can edit"
  1794.         echo "$0 and set ALLOW_ROOT=true instead."
  1795.         exit 1
  1796.     fi
  1797. }
  1798.  
  1799. docommand() {
  1800.     case "$COMMAND" in
  1801.         'console')
  1802.             checkifstartingasroot
  1803.             checkUser touchlock "$@"
  1804.             if [ ! -n "$FIXED_COMMAND" ] ; then
  1805.                 shift
  1806.             fi
  1807.             console "$@"
  1808.             ;;
  1809.  
  1810.         'start')
  1811.             checkifstartingasroot
  1812.             if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
  1813.                 macosxstart
  1814.             elif [ "$DIST_OS" = "linux" -a -f "/etc/init/${APP_NAME}.conf" ] ; then
  1815.                 checkUser touchlock "$@"
  1816.                 upstartstart
  1817.             else
  1818.                 checkUser touchlock "$@"
  1819.                 if [ ! -n "$FIXED_COMMAND" ] ; then
  1820.                     shift
  1821.                 fi
  1822.                 start "$@"
  1823.             fi
  1824.             ;;
  1825.  
  1826.         'stop')
  1827.             checkUser "" "$COMMAND"
  1828.             stopit "0"
  1829.             ;;
  1830.  
  1831.         'graceful')
  1832.             checkUser "" "$COMMAND"
  1833.             graceful "0"
  1834.             ;;
  1835.  
  1836.         'restart')
  1837.             checkUser touchlock "$COMMAND"
  1838.             if [ ! -n "$FIXED_COMMAND" ] ; then
  1839.                 shift
  1840.             fi
  1841.             stopit "0"
  1842.             start "$@"
  1843.             ;;
  1844.  
  1845.         'condrestart')
  1846.             checkUser touchlock "$COMMAND"
  1847.             if [ ! -n "$FIXED_COMMAND" ] ; then
  1848.                 shift
  1849.             fi
  1850.             stopit "1"
  1851.             start "$@"
  1852.             ;;
  1853.  
  1854.         'pause')
  1855.             if [ -n "$PAUSABLE" ]
  1856.             then
  1857.                 pause
  1858.             else
  1859.                 showUsage "$COMMAND"
  1860.             fi
  1861.             ;;
  1862.  
  1863.         'resume')
  1864.             if [ -n "$PAUSABLE" ]
  1865.             then
  1866.                 resume
  1867.             else
  1868.                 showUsage "$COMMAND"
  1869.             fi
  1870.             ;;
  1871.  
  1872.         'status')
  1873.             checkUser "" "$COMMAND"
  1874.             status
  1875.             ;;
  1876.  
  1877.         'install')
  1878.             installdaemon
  1879.             if [ ! `grep ^RUN_AS_USER $0` ]; then
  1880.                  showsetusermesg
  1881.             fi
  1882.             echo
  1883.             echo "You may want to disable the browser from launching at startup at"
  1884.             echo "http://127.0.0.1:7657/configclients"
  1885.             ;;
  1886.  
  1887.         'remove' | 'uninstall')
  1888.             removedaemon
  1889.             ;;
  1890.  
  1891.         'dump')
  1892.             checkUser "" "$COMMAND"
  1893.             dump
  1894.             ;;
  1895.  
  1896.         'start_msg')
  1897.             # Internal command called by launchd on HP-UX.
  1898.             checkUser "" "$COMMAND"
  1899.             startmsg
  1900.             ;;
  1901.  
  1902.         'stop_msg')
  1903.             # Internal command called by launchd on HP-UX.
  1904.             checkUser "" "$COMMAND"
  1905.             stopmsg
  1906.             ;;
  1907.  
  1908.         'launchdinternal')
  1909.             # Internal command called by launchd on Max OSX.
  1910.             # We do not want to call checkUser here as it is handled in the launchd plist file.  Doing it here would confuse launchd.
  1911.             if [ ! -n "$FIXED_COMMAND" ] ; then
  1912.                 shift
  1913.             fi
  1914.             launchdinternal "$@"
  1915.             ;;
  1916.  
  1917.         *)
  1918.             showUsage "$COMMAND"
  1919.             ;;
  1920.     esac
  1921. }
  1922.  
  1923. docommand "$@"
  1924.  
  1925. exit 0
  1926.